﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StableDiffusionTools.Utils
{
    public static class SizeUtil
    {
        public static bool TryParse(string text, out Size size)
        {
            bool result = false;

            string[] split = text?.Split(new string[] { "x", "X" }, StringSplitOptions.RemoveEmptyEntries);
            if (split != null && split.Length == 2 && int.TryParse(split[0], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out int width) && int.TryParse(split[1], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out int height))
            {
                size = new Size(width, height);
                result = true;
            }
            else
            {
                size = Size.Empty;
            }
            return result;
        }
    }
}
